<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Instantiates an SQLite3 object and opens an SQLite 3 database</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="sqlite3.close.html">« SQLite3::close</a></li>
      <li style="float: right;"><a href="sqlite3.createaggregate.html">SQLite3::createAggregate »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.sqlite3.html">SQLite3</a></li>
    <li>Instantiates an SQLite3 object and opens an SQLite 3 database</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="sqlite3.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SQLite3::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SQLite3::__construct</span> &mdash; <span class="dc-title">
   Instantiates an SQLite3 object and opens an SQLite 3 database
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-sqlite3.construct-description">
  <h3 class="title">说明</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SQLite3::__construct</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE</span></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encryptionKey</code><span class="initializer"> = &quot;&quot;</span></span>)</div>

  <p class="para rdfs-comment">
   Instantiates an SQLite3 object and opens a connection to an
   SQLite 3 database. If the build includes encryption, then it will attempt
   to use the key.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-sqlite3.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       Path to the SQLite database, or <code class="literal">:memory:</code> to use in-memory database.
       If <code class="parameter">filename</code> is an empty string, then a private, temporary on-disk
       database will be created. This private database will be automatically
       deleted as soon as the database connection is closed.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
       Optional flags used to determine how to open the SQLite database. By
       default, open uses <code class="literal">SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE</code>.
       <ul class="itemizedlist">
        <li class="listitem">
         <p class="para">
          <code class="literal">SQLITE3_OPEN_READONLY</code>: Open the database for
          reading only.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <code class="literal">SQLITE3_OPEN_READWRITE</code>: Open the database for
          reading and writing.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <code class="literal">SQLITE3_OPEN_CREATE</code>: Create the database if it
          does not exist.
         </p>
        </li>
       </ul>
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">encryptionKey</code></dt>

     <dd>

      <p class="para">
       An optional encryption key used when encrypting and decrypting an
       SQLite database. If the SQLite encryption module is not installed,
       this parameter will have no effect.
      </p>
     </dd>

    
   </dl>

  </p>

 </div>


 <div class="refsect1 errors" id="refsect1-sqlite3.construct-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws an <span class="classname"><a href="class.exception.html" class="classname">Exception</a></span> on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-sqlite3.construct-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.0.10</td>
      <td>
       The <code class="parameter">filename</code> can now be empty to use a private,
       temporary on-disk database.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-sqlite3.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1941">
    <p><strong>示例 #1 <span class="function"><strong>SQLite3::__construct()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$db&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb.db'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'CREATE&nbsp;TABLE&nbsp;foo&nbsp;(bar&nbsp;TEXT)'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;foo&nbsp;(bar)&nbsp;VALUES&nbsp;('This&nbsp;is&nbsp;a&nbsp;test')"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT&nbsp;bar&nbsp;FROM&nbsp;foo'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetchArray</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>